import Vue from 'vue'
var vm = new Vue()


let apis = {}
apis['do_login'] = "/do_login/"
apis['do_project_list'] = "/project_list/"
apis['do_dashboard'] = "/dashboard_json/"
apis['do_workbench'] = "/workbench_json/"


apis['do_remind'] = "/remind_json/"
apis['do_collect'] = "/collect_json/"

let routes = {}
routes['login'] = "/pages/login"
routes['index'] = "/pages/index/index"
routes['project_list'] = '/pages/project_list/index'
routes['dashboard'] = '/pages/dashboard/index'
routes['mine'] = '/pages/mine/index'
routes['remind'] = '/pages/mine/remind'
routes['collect'] = '/pages/mine/collect'

//加载提醒信息填充tabBar Badge数值
function loadReminds() {
	let user_token = uni.getStorageSync("user_token")
	if (!user_token){
		return
	}
	uni.request({
		url: vm.backendServer + apis['do_remind'],
		method: 'get',
		// dataType:'application/json',
		data: {
			'user_id': user_token
		},
		success: (res) => {
			uni.hideLoading()
			if (res.data.status) {
				let totalUnreadRemindSize = res.data.results.unread_count
				console.log('totalUnreadRemindSize ', totalUnreadRemindSize)
				if (user_token && totalUnreadRemindSize) {
					uni.setTabBarBadge({
						index: 3,
						text: totalUnreadRemindSize + ''
					})
				}
			} else {
				uni.showToast({
					title: "获取失败，" + res.data.msg,
					icon: 'fail'
				})
				uni.switchTab({
					url: routes['dashboard']
				})
				// this.project_list = []
			}
		},
		fail: (res) => {
			uni.hideLoading()
			console.log('fail res ', res)
			uni.showToast({
				title: "获取失败，请检查网络联接，" + res,
				icon: 'fail'
			})
			uni.switchTab({
				url: routes['dashboard']
			})
			// this.project_list = []
		}
	})
}


export {
	apis,
	routes,
	loadReminds
}